<?php

class commentArticle extends Model
{

	function getComment($id)
	{
		$gcomment = $this->db->getAll("SELECT article.post,
				ca.comment_id,
				ca.stud_no, 
				ca.date,
				ca.comment,
				organization.name Org,
				user.lastname, 
				user.firstname,
				user.middlename
			FROM article,organization, commentarticle ca, user
			WHERE article.org_id = organization.org_id 
			AND ca.stud_no = user.stud_no
			AND ca.article_id = article.article_id
			AND article.article_id = ?
			ORDER BY ca.date ASC",
			array($id));
		return $gcomment;
	}

	function insertComment ( $article_id, $stud_no, $date, $comment )
	{
		$icomment = $this->db->execute("INSERT INTO commentarticle( article_id,
			stud_no,
			date,
			comment )
			VALUES ( ?, ?, ?, ? )", 
			array( $article_id, $stud_no, $date, $comment )
		);
		return $icomment;
	}

	function updateComment( $article_id, $stud_no, $date, $comment, $comment_id ) 
	{
		$ucomment = $this->db->execute("UPDATE commentarticle
			SET article_id = ?,
			stud_no = ?,
			date = ?,
			comment = ?			
			WHERE comment_id = ?",
			array( $article_id, $stud_no, $date, $comment, $comment_id  )
		);
		return $ucomment;
	}

	function deleteComment ( $comment_id )
	{
		$dphoto = $this->db->execute("DELETE FROM commentarticle
			WHERE comment_id  = ? ",
			array( $comment_id  )
		);
	}
}